package com.sense.kukoo.common.night

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import com.sense.kukoo.common.repo.Repo

class DayNightManager {

    companion object{

        private val TAG: String = DayNightManager::class.java.simpleName

        fun init(){
            val mode = getMode()
            AppCompatDelegate.setDefaultNightMode(mode)
        }

        fun getMode():Int{
            val def = AppCompatDelegate.MODE_NIGHT_NO
            return Repo.dayNightMode.get(def)
        }

        //设置mode,在activity recreate()后生效
        fun setMode(mode:Int, activity: AppCompatActivity){
            //保存
            Repo.dayNightMode.set(mode)
            //
            activity.getDelegate().setLocalNightMode(mode)
            AppCompatDelegate.setDefaultNightMode(mode)
        }
    }
}